package com.bishe.demo.modules.hotel.hotelPolicy.dao;

import com.bishe.demo.modules.account.entity.User;
import com.bishe.demo.modules.hotel.hotelPolicy.entity.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface PolicyDao {
    @Insert("insert into hotel_policy values(#{policyId},#{attention},#{allowChild},#{pet},#{limitAge})")
    void insertPolicy(Policy policy);

    @Select("select * from hotel_policy where policy_id=#{userId}")
    Policy getPolicyByUserId(int userId);

    @Select("select * from hotel_policy where policy_id=#{hotelId}")
    @Results(id = "policyResult", value = {
            @Result(property = "policyId", column = "policy_id"),
            @Result(property = "check", column = "policy_id",
                    javaType = Check.class,
                    one = @One(select = "com.bishe.demo.modules.hotel.hotelPolicy.dao.CheckDao.getCheckByPolicyId")),
            @Result(property = "checkType", column = "policy_id",
                    javaType = CheckType.class,
                    one = @One(select = "com.bishe.demo.modules.hotel.hotelPolicy.dao.CheckTypeDao.getCheckTypeByPolicyId")),
            @Result(property = "addBed", column = "policy_id",
                    javaType = AddBed.class,
                    one = @One(select = "com.bishe.demo.modules.hotel.hotelPolicy.dao.AddBedDao.getAddBedByPolicyId")),
            @Result(property = "breakfast", column = "policy_id",
                    javaType = Breakfast.class,
                    one = @One(select = "com.bishe.demo.modules.hotel.hotelPolicy.dao.BreakfastDao.getBreakfastByPolicyId")),
            @Result(property = "parking", column = "policy_id",
                    javaType = Parking.class,
                    one = @One(select = "com.bishe.demo.modules.hotel.hotelPolicy.dao.ParkingDao.getParkingByPolicyId")),
            @Result(property = "user", column = "policy_id",
                    javaType = User.class,
                    one = @One(select = "com.bishe.demo.modules.account.dao.UserDao.getUserByPolicyId")),
    })
    Policy getPolicyByHotelId(int hotelId);

    @Delete("delete from hotel_policy where policy_id=#{policyId}")
    void deletePolicyByPolicyId(int policyId);
}
